﻿using MediatR;
using Rabbit.Domain;
using Rabbit.ErCode;
using Rabbit.lnfarnum;
using Rabbit.Write.API.WriteRepository.Commder;

namespace Rabbit.Write.API.WriteRepository.CommdHnader
{
    public class UpdateMerchanCommdHander : IRequestHandler<UpdateMerchanCommd, APIResult<object>>
    {

        private readonly IBaseRepository<MerchandiseMangem> baseRepository;

        public UpdateMerchanCommdHander(IBaseRepository<MerchandiseMangem> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<object>> Handle(UpdateMerchanCommd request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();

            result.Code = ReCode.修改成功;
            result.Mage = ReCode.修改成功.ToString();


            var list = baseRepository.GetAll().FirstOrDefault(X => X.MerchandMangeid == request.MerchandMangeid);

            list.MerchanMid=request.MerchanMid;
            list.Pbatches = request.Pbatches;
            list.Slfsky = request.Slfsky;
            list.Plinumber = request.Plinumber;
            list.ManufacName = request.ManufacName;
            list.Coverimage = request.Coverimage;
            list.Complete = request.Complete;
            list.Propection = list.Propection;

            baseRepository.Update(list);
            return Task.FromResult(result);

        }
    }
}
